const {login3,getadmins3,updateOne3, deleteOne3, search3, addOne3} = require('../dao/adminsDao');
const updateStatistics = require('../dao/totalStatisticsDao')
module.exports.login2 = async loginData => {
    const data = await login3(loginData);
    if(data.length > 0 && data[0].state) {
        return true
        
    } else {
        return false
    }
}

module.exports.getadmins2 = async function({adminname}){
   //判断传过来的adminname是否有值，有的话查询，没有返回全部信息
    if(adminname) {
        return await search3(adminname)
    } else {
     return await getadmins3();
    }  
}



module.exports.updateOne2 = async updateState => {
    const data = await updateOne3(updateState );
    if(data.ok == 1) {
        return true;
    }
    return false;
}

module.exports.deleteOne2 = async function (adminId) {
    const data = await deleteOne3(adminId);
    if(data.deletedCount == 1) {
        return true;
    }
    return false;
 }

 module.exports.addOne2 = async function (newadmin) {
    const data = await addOne3(newadmin)
    if(data._id) {
        updateStatistics("admins");
        return true
    }
    return false
}